package com.ws.test09.util;

import com.ws.test09.entity.Student;

import java.util.Comparator;

/**
 * @author 王硕
 * @version jdk21
 * @className StudentComparator
 * @description
 * @date 2024/11/22 8:59
 */
public class StudentComparator implements Comparator<Student> {
    @Override
    public int compare(Student s1, Student s2) {
        // 先按成绩降序排序
        if (s1.getScore() != s2.getScore()) {
            return Double.compare(s2.getScore(), s1.getScore());
        }
        // 成绩相同，按年龄升序排序
        return Integer.compare(s1.getAge(), s2.getAge());
    }
}
